﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Runtime.Serialization;

namespace YPD.Common.Model
{
    /// <summary>
    /// 请求返回结果包装类
    /// </summary>
    [Serializable]
    [DataContract]
    public class ReturnPakect<T>
    {
        /// <summary>
        /// 是否出现异常
        /// </summary>
        [DataMember]
        public bool IsError { set; get; }

        /// <summary>
        ///返回数据
        /// </summary>

        [DataMember]
        public T Data { set; get; }

        /// <summary>
        ///  描述信心，如果IsSuccess=false时 则为异常信息
        /// </summary>
        [DataMember]
        public string Message { set; get; }

        public ReturnPakect()
        {
            IsError = false;
        }

        /// <summary>
        /// 设置访问失败
        /// </summary>
        /// <param name="info"></param>
        public void SetError(string info)
        {
            IsError = true;
            Message = info;
        }

        /// <summary>
        /// 设置访问成功
        /// </summary>
        /// <param name="data"></param>
        public void SetSuccess(T data)
        {
            IsError = false;
            Data = data;
        }

        /// <summary>
        /// 设置访问成功并设置附带消息内容
        /// </summary>
        /// <param name="data"></param>
        /// <param name="mess"></param>
        public void SetSuccess(T data, string mess)
        {
            IsError = false;
            Data = data;
            Message = mess;
        }

    }

    #region 单例模板
    /// <summary>
    ///  单例模板
    /// </summary>
    public class Singleton<T> where T : new()
    {
        public static T Instance
        {
            get { return TempeCreator<T>.Instance; }
        }
    }
    class TempeCreator<T> where T : new()
    {
        static TempeCreator() { }

        internal static readonly T Instance = new T();
    }
    #endregion

    public class PagerData<T>
    {
        /// <summary>
        /// 总数据行数
        /// </summary>
        public int RowCount { set; get; }

        /// <summary>
        ///数据总页数
        /// </summary>
        public int PageCount { set; get; }

        /// <summary>
        /// 页宽（每页显示多少数据）
        /// </summary>
        public int PageSize { set; get; }

        /// <summary>
        /// 当前页数据
        /// </summary>
        //public List<T> PageData { set; get; }

        public List<T> PageData { set; get; }

        /// <summary>
        /// 
        /// </summary>
        public int PageIndex { set; get; }
    }

    public class BackstageLoginCache
    {

        /// <summary>
        /// 访问过期时间
        /// </summary>
        public int TimeOutLength = 20;
        /// <summary>
        /// 用户ID
        /// </summary>
        public string UserId { set; get; }

        /// <summary>
        ///  用户名
        /// </summary>
        public string UserName { set; get; }

        /// <summary>
        /// 用户权限码
        /// RightCode: 1、凉山普通用户 ；2、凉山管理员 ；3、攀枝花普通用户 ；4、攀枝花管理员 ；5、财务；6、网站管理
        /// </summary>
        public string RightCode { set; get; }

        /// <summary>
        /// 会话token
        /// </summary>
        public string Token { set; get; }

        /// <summary>
        /// 过期时间
        /// </summary>
        public DateTime TimeOut { set; get; }


        /// <summary>
        /// 刷新登录过期时间
        /// </summary>
        public void FreshTimeOut()
        {
            this.TimeOut = DateTime.Now.AddMinutes(this.TimeOutLength);
        }
    }
}
